
var reader = require("id3-reader");
const readline = require('readline');
var fs = require("fs");
var path=require("path");
var infoList=[];
var inputNum=0;

console.log("公共资源目录路径:")
const currentPath=readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
var inputContent="";
var srcPath="";
currentPath.on('line',function (inputarr) {

    if(inputNum==0){
        inputContent=inputarr.split(" ").toString();
        inputNum++;
        console.log("资源所在文件夹:");
    }else {
        srcPath = inputarr.split(" ").toString();
        let files = fs.readdirSync(srcPath);
        console.log("正在生成......");
        for (let i = 0; i < files.length; i++) {
            (function (i) {

                var staticpath = srcPath + "/" + files[i];
                reader(staticpath).then(infos => {

                    let info = {

                        imgsrc: "",//音乐海报
                        audiosrc: inputContent + "/" + files[i],//音乐相对路径
                        audiotitle: infos.title,//音乐名字
                        singer: infos.singer,//歌手
                        album: infos.album//专辑
                    };

                    infoList.push(info);
                    if(i==files.length-1){

                        console.log(infoList);
                    }
                });
            })(i)

        }

    }

});

